package cn.cqie.frame.controller;


import cn.cqie.frame.bo.query.QueryClassBo;
import cn.cqie.frame.entity.Clazz;
import cn.cqie.frame.service.ClazzService;
import cn.cqie.frame.utils.MyPageHelper;
import cn.cqie.frame.vo.ClassVo;
import cn.cqie.frame.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHL
 * @since 2021-10-09
 */
@RestController
@Api("班级管理")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @ApiOperation("新增/更新班级信息")
    @PostMapping(value = "/class/saveOrUpdateClass")
    public ResultVo<Clazz> saveOrUpdateClass(@Valid @RequestBody Clazz bo) {
        Clazz clazz = clazzService.saveOrUpdateClass(bo);
        return ResultVo.success(clazz);
    }
    @ApiOperation("查询班级信息分页")
    @GetMapping(value = "/class/classInfoPage")
    public ResultVo<PageInfo<ClassVo>> getPageList(QueryClassBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(clazzService.list(bo)));
    }
    @ApiOperation("删除班级")
    @DeleteMapping("/class/deleterClass/{classId}")
    public ResultVo<Void> deleterClass(@PathVariable Integer classId) {
        Boolean aBoolean = clazzService.deleterClass(classId);
        return aBoolean ? ResultVo.success() : ResultVo.error("删除失败");
    }


}

